home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Inspectors / ssi_widget.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  3.1 KB  |  145 lines

  1. // Copyright 1999 Macromedia, Inc.  All rights reserved.
  2.  
  3. // *********** GLOBAL VARS *****************************
  4.  
  5. var helpDoc = MM.HELP_inspSsiCommon;
  6.  
  7. // ******************** API ****************************
  8.  
  9.  
  10. function canInspectSelection() 
  11. {
  12.  
  13.     var curSelection    = dreamweaver.getSelection();
  14.     var includeStr;
  15.     var tempStr;
  16.     var theObj            = dreamweaver.offsetsToNode(curSelection[0],curSelection[1]);
  17.  
  18.     
  19.     if (theObj.nodeType == Node.COMMENT_NODE) 
  20.     {
  21.         tempStr        = theObj.data;
  22.         includeStr    = tempStr.toLowerCase().indexOf("#include");
  23.  
  24.         if (includeStr != -1) 
  25.         {
  26.             return "true";
  27.         }
  28.         else
  29.         {
  30.              return "false"; 
  31.         }
  32.     } 
  33.     else
  34.     {
  35.          return "false";
  36.     }
  37. }
  38. function inspectSelection() 
  39. {
  40.     var result = dreamweaver.getSelection();
  41.     var theObj = dreamweaver.offsetsToNode(result[0],result[1]);
  42.     var fileStr,virtualStr,quoteStr,tempStr,includeStr,quoteStrLast;
  43.      if (theObj.nodeType != Node.COMMENT_NODE) 
  44.         return;
  45.  
  46.     tempStr                = theObj.data;
  47.     fileStr                = tempStr.toLowerCase().indexOf("file");
  48.     virtualStr            = tempStr.toLowerCase().indexOf("virtual");
  49.     quoteStr            = tempStr.indexOf('"');
  50.     quoteStrLast        = tempStr.lastIndexOf('"');
  51.     includeStr            = tempStr.toLowerCase().indexOf("#include");
  52.     var fileRadObj        = findObject("radioFile");
  53.     var virtualRadObj    = findObject("radioVirtual");
  54.     gOrignalURL            = tempStr.substring(quoteStr+1,quoteStrLast);
  55.     findObject("editField").value  = gOrignalURL;
  56.         
  57.     gOrignalRadio = ssiType( tempStr.toLowerCase() );
  58.     if ( gOrignalRadio == "virtual" )
  59.     {
  60.         virtualRadObj.checked    = true;
  61.         fileRadObj.checked        = false;
  62.     }
  63.     else 
  64.     {
  65.         fileRadObj.checked        = true; 
  66.         virtualRadObj.checked    = false;
  67.     } 
  68.  
  69. }    
  70.  
  71. // whichButton is 0 for no button clicked, 1 for the virtual button,
  72. // 2 for the file button
  73. function setComment(whichButton) 
  74. {
  75.     var result = dreamweaver.getSelection();
  76.     var theObj = dreamweaver.offsetsToNode(result[0],result[1]);
  77.  
  78.     if (theObj.nodeType != Node.COMMENT_NODE) 
  79.         return;
  80.  
  81.     tempStr = theObj.data;
  82.     var radioStr;
  83.     var fileRadObj = findObject("radioFile");
  84.     var virtualRadObj = findObject("radioVirtual");
  85.     if (whichButton == 1) 
  86.     {
  87.         // virtual button was checked
  88.         fileRadObj.checked = false;
  89.         virtualRadObj.checked = true;
  90.     } 
  91.     else if (whichButton == 2)
  92.      {
  93.         // file button was checked
  94.         virtualRadObj.checked = false;
  95.         fileRadObj.checked = true;
  96.     }
  97.     
  98.     var URL = findObject("editField").value;
  99.         if (fileRadObj.checked) 
  100.         {
  101.             // verify that it's okay as a file-type URL
  102.  
  103.  
  104.             radioStr = "file";
  105.             if (URL.charAt(0) == '/' || URL.indexOf("../") != -1)
  106.             {
  107.                 var fileURL;
  108.                 
  109.                 relativeURL = findObject("editField").value;
  110.                 fileURL = virtualToFile(relativeURL);    
  111.  
  112.                 if ( fileURL == "" )
  113.                 {        
  114.                     radioStr = "virtual";
  115.                     virtualRadObj.checked = true;
  116.                     fileRadObj.checked = false;
  117.                     return;
  118.                 }
  119.                 else
  120.                 {
  121.                     URL = fileURL;
  122.                     findObject("editField").value = fileURL;
  123.                 }
  124.  
  125.             }    
  126.             
  127.             // file button was checked
  128.             virtualRadObj.checked    = false;
  129.             fileRadObj.checked        = true;    
  130.         } 
  131.         else 
  132.         {
  133.             radioStr = "virtual";
  134.             virtualRadObj.checked    = true;
  135.             fileRadObj.checked        = false;
  136.         }
  137.  
  138.         if ( unchanged( radioStr, URL ) )
  139.             return;
  140.  
  141.     theObj.data =  "#include " + radioStr + "=" + '"' + URL + '" ';
  142.  
  143. }
  144.  
  145.